package com.gtm.repository;

import com.gtm.model.User;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.data.mongodb.repository.Query;

import javax.persistence.Entity;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

/**
 * Created by dell on 2017/10/25.
 */
/*
  业务接口
 */
public interface UserRepository extends MongoRepository<User, String> {
    //继承MongoRepository<T, ID>接口   T：操作的model   该接口实现了CRUD方法
    User findByUsernameAndPasswd(String username, String password);


    List<User> findByTypeIn(ArrayList<Byte> typelist);

    @Query(value = "{$and:[{username:?0},{detail.email:?1}]}")
    User findByUsernameAndEmail(String username, String email);

    User findByUsername(String username);

    List<User> findByType(byte type);

    List<User> findByTopicIdAndSelectTopicState(String id, String selected);

    List<User> findByTopicId(String id);

    List<User> findByTopicIdAndSelectTopicStateAndRealnameLike(String s, String selected, String stuName);

    @Query(value = "{'additionalData.state':?0}")
    List<User> findByState(String state);

    @Query(value = "{'additionalData.state':{$in:?0}}")
    List<User> findByStateIn(List<String> state);

    @Query(value = "{$and:[{'additionalData.state':?0},{$or:[{'username':{$regex:?1}},{'realname':{$regex:?1}}]}]}")
    Page<User> findByAddSta0teInWithSearchKey(Pageable pageRequest, String state, String searchKey);

    @Query(value = "{'additionalData.state':?0}")
    Page<User> findByAddSta0teIn(Pageable pageRequest, String state);

    List<User> findByTypeIsAndIdNot(Byte type, String teacherId);
}
